import { axiosInstance } from 'src/boot/axios'
import CommonConfig from '../../assets/js/config'
const baseUrlProduct = CommonConfig.processUrl + '/v1'

/**
 * 获取工艺路线模板
 * @param params
 */
export function getRouteTemplate (params) {
  const newUrl = `${baseUrlProduct}/process_route_templates`

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}
/**
 * 创建工艺路线模版
 * @param data
 */
export function createRouteTemplate (data) {
  const newUrl = `${baseUrlProduct}/process_route_templates`

  return axiosInstance.post(newUrl, data).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 编辑工艺路线模版
 * @param id
 * @param data
 */
export function updateRouteTemplate (id, data) {
  const newUrl = `${baseUrlProduct}/process_route_templates/${id}`

  return axiosInstance.put(newUrl, data).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 删除工艺路线模版
 * @param id
 */
export function deleteRouteTemplate (id) {
  const newUrl = `${baseUrlProduct}/process_route_templates/${id}`

  return axiosInstance.delete(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 删除工艺路线模版
 * @param id
 */
export function useRouteTemplate (id, data) {
  const newUrl = `${baseUrlProduct}/process_route_templates/${id}:use`

  return axiosInstance.post(newUrl, data).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 校验名称是否重复
 * @param data
 */
export function checkRouteTemplate (data) {
  const newUrl = `${baseUrlProduct}/process_route_templates/name:repeatCheck`

  return axiosInstance.get(newUrl, { params: data }).then((res) => {
    return Promise.resolve(res)
  })
}
